package elion.com.theElion.fragmentMain;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import elion.com.elion.R;
import elion.com.theElion.util.MyFragmentPagerAdapter;

/**
 * Created by xiaon on 2017/6/6.
 */

public abstract class MyTabFragment extends Fragment {

    protected ViewPager viewPager;
    protected TabLayout tabLayout;

    protected MyFragmentPagerAdapter adapter;

    protected String[] titles;
    protected List<Fragment> fragments;
    protected View mView;
//    private Toolbar toolbar;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_my_tab, container, false);

        findView();
        initData();
        setting();
        return mView;
    }


    private void initData() {

        this.fragments = setFragment();
        this.titles = setTitles();
        adapter = new MyFragmentPagerAdapter(getChildFragmentManager(),
                getActivity());
        adapter.setContentList(fragments);
        adapter.setContentTitles(titles);
        viewPager.setOffscreenPageLimit(4);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayoutSetting();

    }

    public void findView() {
        tabLayout = (TabLayout) mView.findViewById(R.id.tl_land_data);
        viewPager = (ViewPager) mView.findViewById(R.id.viewPager);

//        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

    }

    public abstract List<Fragment> setFragment();

    public abstract String[] setTitles();

    public abstract void setting();

    public abstract void tabLayoutSetting();

}
